<template>
  <div class="content-right">

    <!-- <div class="right-top"
      v-if="dialogAlarmInfo.status == '3' && (user.tenantId == '1762803843806539777' || user.tenantId == '1770292338296893442' || user.tenantId == '1772837590137270273')">
      <div class="title">火情通知结果</div>
      <div class="answer" v-if="tableData !== null">
        <div style="
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
          " v-if="tableData && tableData.length > 0">
          <div class="item" v-for="(item, index) in tableData" :key="index">
            <div class="row">
              <div class="label">
                <i class="iconfont shoujihao img"></i>
                手机号：
              </div>
              <span>{{ item.mobile }}</span>
            </div>
            <div class="row">
              <div class="label">
                <i class="iconfont jieting img"></i>
                接听状态：
              </div>
              <span> <span v-if="item.code == 0" type="success">已接听</span>
                <span v-else-if="item.code == 1" type="danger">关机</span>
                <span v-else-if="item.code == 2" type="danger">通话中</span>
                <span v-else-if="item.code == 3" type="warning">不在服务区</span>
                <span v-else-if="item.code == 4" type="warning">您拨打的号码已欠费</span>
                <span v-else-if="item.code == 5" type="warning">无人接听</span>
                <span v-else-if="item.code == 6" type="warning">暂时无法接通</span>
                <span v-else-if="item.code == 7" type="warning">停机</span>
                <span v-else-if="item.code == 8" type="warning">空号</span>
                <span v-else-if="item.code == 9" type="warning">电路正忙</span>
                <span v-else-if="item.code == 10" type="warning">用户正忙</span>
                <span v-else-if="item.code == 11" type="warning">其他原因</span>
                <span v-else-if="item.code == 12" type="warning">呼叫受限，请勿越权使用</span>
                <span v-else-if="item.code == 13" type="warning">您拨打的号码已暂停服务</span>
                <span v-else-if="item.code == 15" type="warning">号码不存在</span>
                <span v-else-if="item.code == 16" type="warning">来电提醒</span>
                <span v-else-if="item.code == 17" type="warning">您拨打的号码已过期</span>
                <span v-else-if="item.code == 18" type="warning">网络忙</span>
                <span v-else-if="item.code == 19" type="warning">未开通语音通话功能</span>
                <span v-else-if="item.code == 20" type="warning">无应答</span>
                <span v-else-if="item.code == 22" type="warning">系统正忙</span>
                <span v-else-if="item.code == 23" type="warning">加拨零</span>
                <span v-else-if="item.code == 24" type="warning">您拨打的号码已改号</span>
                <span v-else-if="item.code == 25" type="warning">未开通联通秘书服务</span>
                <span v-else-if="item.code == 26" type="warning">来电助手</span>
                <span v-else-if="item.code == 27" type="warning">暂时无法接通</span>
                <span v-else-if="item.code == 28" type="warning">漏话提醒服务</span>
                <span v-else-if="item.code == 29" type="warning">留言信箱</span>
                <span v-else-if="item.code == 30" type="warning">您拨打的号码有误</span>
                <span v-else-if="item.code == 31" type="warning">不在使用中</span>
                <span v-else type="danger">呼出失败</span></span>
            </div>
            <div class="row">
              <div class="label">
                <el-image :src="srcTime" class="img"></el-image>发起时间：
              </div>
              <span>{{ item.startCallTime }}</span>
            </div>
            <div class="row">
              <div class="label">
                <el-image :src="answer" class="img"></el-image>接听时间：
              </div>
              <span>{{ item.acceptTime }}</span>
            </div>
            <div class="row">
              <div class="label">
                <el-image :src="endtime" class="img"></el-image>结束时间：
              </div>
              <span>{{ item.endCallTime }}</span>
            </div>
          </div>
        </div>
        <div v-else style="height: 90%; display: flex;  flex-direction: column;
          align-items: center;
          justify-content: center;">
          <el-image :src="wugj" style="width: 120px; height: 120px;margin-bottom: 10px;"></el-image>
          <div>暂无数据</div>
        </div>
      </div>
    </div>

    <div class="right-top" v-else>
      <div class="title">{{ user.tenantId == '1762803843806539777' || user.tenantId == '1770292338296893442' ||
        user.tenantId == '1772837590137270273' ? '火情通知' : '接警人'
      }}</div>
      <div class="fireChief">
        <el-collapse v-model="activeName" accordion>
          <el-collapse-item :title="item.name" :name="item.id" v-for="item in targelist" :key="item.id">
            <div v-if="item.dataList && item.dataList.length > 0">
              <div class="citem" v-for="citem in item.dataList" :key="citem.id">
                <span class="mobile">{{ citem.mobile }}</span>
                {{ citem.name }}
              </div>
            </div>
            <div v-else>暂无设置</div>
          </el-collapse-item>
        </el-collapse>
      </div>
    </div> -->

    <div class="right-bottom">
      <div class="title">平面图</div>
      <div class="no-data">
        <div ref="mapContainer" style="
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            position: relative;
            cursor: pointer;
            overflow: hidden;
          " @click="clickIchnography" v-if="flag">
          <img class="elImage" :src="img" />
          <!-- <i class="el-icon-location icon" :style="'top:' + item.top + 'px;' + 'left:' + item.left + 'px;'"
            v-for="(item, index) in markVOList" :key="index" :class="iconclass(item)">
          </i> -->
          <i class="icon" :style="'top:' + item.top + '; left:' + item.left + ';'" v-for="(item, index) in markVOList"
            :key="index" :class="iconclass(item)">
          </i>
        </div>
        <div v-else
          style="height: 90%; display: flex;flex-direction: column; align-items: center;justify-content: center;">
          <el-image :src="wugj" style="width: 120px; height: 120px;margin-bottom: 10px;"></el-image>
          <div>暂无平面图</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  reqFloorById,
  reqGetByTargetId,
  reqGetMark,
  reqPageVoiceLog
} from "@api/api.js";
import { mapState } from "vuex";

export default {
  props: ["dialogAlarmInfo"],
  components: {},
  data() {
    return {
      wugj: require("@assets/images/datav/wugj.png"),
      img: require("@assets/images/xiaofang.png"),
      // 接警人
      targelist: [
        { id: 1, name: "一级接警人", dataList: [] },
        { id: 2, name: "二级接警人", dataList: [] },
        { id: 3, name: "三级接警人", dataList: [] },
        { id: 4, name: "四级接警人", dataList: [] },
      ],
      activeName: null,

      // 平面图
      markVOList: [],
      left: 0,
      top: 0,
      flag: true,
      page: 1,
      limit: 99,
      total: 0,
      tableData: [],
      srcAlarm: require("@assets/images/datav/record_alarm.png"),
      srcPerson: require("@assets/images/datav/record_person.png"),
      srcTime: require("@assets/images/datav/record_time .png"),
      srcContent: require("@assets/images/datav/record_content.png"),
      srcImg: require("@assets/images/datav/record_img.png"),
      answer: require("@assets/images/datavPop/answer.png"),
      endtime: require("@assets/images/datavPop/endtime.png"),
      containerWidth: 0,
      containerHeight: 0,
    };
  },
  computed: {
    ...mapState(["user"]),
  },
  watch: {},
  methods: {
    async PageSmsLog(id) {
      // console.log(id, "id");
      let res = await reqPageVoiceLog(this.page, this.limit, {
        orgId: "",
        phone: '',
        imei: '',
        result: '',
        code: '',
        startTime: '',
        endTime: '',
        alarmId: id,
      });
      // console.log(res);
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.tableData = res.data.rows;
      this.total = res.data.total;
    },
    // 标记点颜色
    // iconclass(e) {
    //   // console.log(e);
    //   if (e.isAlarm == 1) {
    //     return "hon";
    //   }
    //   if (e.online == 0) {
    //     return "lixian";
    //   }
    // },
    // 标记点图片
    iconclass(e) {
      let pic = 'iconfont shebeiguanli2'
      if (e.productName == '门磁') {
        pic = 'iconfont menci'
      } else if (e.productName == '烟感探测报警器') {
        pic = 'iconfont yangan'
      } else if (e.productName == '红外探测器') {
        pic = 'iconfont rentihongwai'
      } else if (e.productName == '智能燃气报警器') {
        pic = 'iconfont reshuiqi'
      }
      return pic
    },
    //获取平面图设备标点
    async getgetMark(floorId) {
      this.containerWidth = this.$refs.mapContainer.offsetWidth;
      this.containerHeight = this.$refs.mapContainer.offsetHeight;

      // 原始平面图的宽度和高度
      const originalWidth = 800;
      const originalHeight = 450;

      const res = await reqGetMark(1,10,{
        floorId: floorId,
        imei:this.dialogAlarmInfo.imei
      });
      this.markVOList = res.data.row.markVOList || [];
      if (this.markVOList.length == 0) return;
      this.markVOList = this.markVOList.filter((item) => item.mark != "");
      // this.markVOList.forEach((item) => {
      //   item.left = (item.mark.slice(0, item.mark.indexOf(",")) / 2).toFixed(2);
      //   item.top = (item.mark.slice(item.mark.indexOf(",") + 1) / 1.7).toFixed(
      //     2
      //   );
      // });

      this.markVOList = (res.data.row.markVOList || []).map(item => {
        // 确保mark存在且包含逗号分隔的x和y坐标
        if (item.mark && item.mark.includes(",")) {
          const [x, y] = item.mark.split(",");
          // 将原始坐标转换为相对于原始尺寸的百分比
          const percentX = parseFloat(x) / originalWidth;
          const percentY = parseFloat(y) / originalHeight;
          // 将百分比转换为当前容器的像素坐标
          const left = (percentX * this.containerWidth).toFixed(2) - 5 + 'px';
          const top = (percentY * this.containerHeight).toFixed(2) + 'px';
          // 返回更新后的对象
          return { ...item, left, top };
        }
        // 如果mark格式不正确，返回原始对象（或根据需要处理）
        return item;
      });
      // 过滤掉没有有效left和top属性的项（可选）
      this.markVOList = this.markVOList.filter(item => item.left && item.top);
      // console.log(this.markVOList, 'this.markVOList');
    },
    // 查询平面图
    async getFloorById(spaceId) {
      const res = await reqFloorById(spaceId);
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      if (res.data.rows.image == "") {
        this.flag = false;
      } else {
        this.flag = true;
      }
      this.img = res.data.rows.image;
      this.getgetMark(res.data.rows.id)//楼层id
    },
    // 查看平面图
    async clickIchnography() {
      this.$emit("clickIchnography");
      // this.getVoice()
      // const res = await reqFloorById(this.dialogAlarmInfo.spaceId);
      // if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      // if (res.data.rows.image == '') return this.$modal.notifyWarning('当前楼层暂无平面图,请上传后操作!');
      // this.$refs.refIchnography.dialogVisible = true;
      // this.$refs.refIchnography.getimage(res.data.rows.image)
      // this.$refs.refIchnography.getGetMark(this.dialogAlarmInfo.spaceId)
    },
    // 安装点id获取接警人列表
    async getByTargetId(spaceId) {
      let res = await reqGetByTargetId(spaceId);
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      // console.log(res);
      // this.targelist = res.data.rows || [];
      res.data.rows.forEach((item) => {
        this.targelist[item.level - 1].dataList.push(item);
      });
      setTimeout(() => {
        this.activeName = 1;
      }, 200);
    },
    getIconStyle(item) {
      const left = (this.containerWidth * item.left).toFixed(2) + 'px';
      const top = (this.containerHeight * item.top).toFixed(2) + 'px';
      return {
        top,
        left,
      };
    },
    handleResize() {
      this.containerWidth = this.$refs.mapContainer.offsetWidth;
      this.containerHeight = this.$refs.mapContainer.offsetHeight;
      // 如果需要，可以在窗口大小改变时重新计算图标的位置
    },
  },
  created() { },
  mounted() {
    // this.containerWidth = this.$refs.mapContainer.offsetWidth;
    // this.containerHeight = this.$refs.mapContainer.offsetHeight;
    // window.addEventListener('resize', this.handleResize);
  },
  beforeDestroy() {
    // window.removeEventListener('resize', this.handleResize);
  },
};
</script>

<style lang='less' scoped>
.fontSize (@px, @attr: font-size) {
  @vw: (@px / 1920) * 100;
  @{attr}:~"@{vw}vw";
}

.lineHeight (@px, @attr: line-height) {
  @vh: (@px / 1080) * 100;
  @{attr}:~"@{vh}vh";
}

.width (@px, @attr: width) {
  @vw: (@px / 1920) * 100;
  @{attr}:~"@{vw}vw";
}

.height (@px, @attr: height) {
  @vh: (@px / 1080) * 100;
  @{attr}:~"@{vh}vh";
}

.content-right {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .title {
    .height(43);
    width: 100%;
    margin: 0 auto;
    .fontSize(16);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url("../../../assets/images/datavPop/head.png") no-repeat;
    background-size: 100% 100%;
    font-weight: 600;
  }

  .right-top {
    height: calc(55% - 1.5vh);
    // flex: 1;
    box-shadow: inset -9px 3px 20px 0px #032b60, inset 9px -3px 20px 0px #032e68;
    margin-bottom: 1.5vh;

    .answer {
      height: 86%;
      overflow-y: auto;
      color: #fff;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      align-items: center;

      .item {
        width: 80%;
        padding: 12px 15px;
        margin-bottom: 10px;
        background: linear-gradient(#062359, rgba(4, 21, 177, 0.38), #061559);
        border-radius: 5px;

        &:first-child {
          margin-top: 10px;
        }

        .row {
          .fontSize(16);
          color: #ffffff;
          margin-bottom: 6px;
          display: flex;
          align-items: flex-end;

          .label {
            color: #8299c9;
            .fontSize(16);

            white-space: nowrap;
            display: flex;
            align-items: center;

            .img {
              width: 15px;
              height: 15px;
              margin-right: 5px;
            }
          }

          .img1 {
            width: 50px;
            height: 40px;
          }
        }
      }
    }

    .fireChief {
      height: calc(86% - 10px);
      overflow-y: auto;
      color: #fff;
      margin-top: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;

      .citem {
        margin-bottom: 2px;

        .mobile {
          margin-right: 10px;
        }
      }
    }
  }

  .right-bottom {
    height: 100%;
    box-shadow: inset -9px 3px 20px 0px #032b60, inset 9px -3px 20px 0px #032e68;

    .no-data {
      width: 100%;
      height: 89%;

      .elImage {
        width: 100%;
        height: 100%;
      }
    }
  }
}

.icon {
  position: absolute;
  border-radius: 50%;
  font-size: 18px;
  width: 32px;
  height: 32px;
  background-color: #7367F0;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}

.hon {
  color: #f84242;
}

.lixian {
  color: #90a4ae;
}



// 折叠
.el-collapse {
  width: 90%;
  border-top: none;
  border-bottom: none;
  border-radius: 5px !important;
}

::v-deep .el-collapse-item__header {
  color: #8299c9;
  // font-size: 14px;
  font-size: 0.8vw;
  // background: linear-gradient(#073068 rgba(6, 33, 152, 0.38), #071867);
  background-color: #041355;
  border: none;
  padding-left: 10px;
  border-radius: 5px !important;
}

::v-deep .el-collapse-item__content {
  color: #fff;
  font-size: 0.8vw;
  border: none !important;
  padding: 10px 0 10px 10px;
  background-color: transparent !important;
  border-radius: 0 0 5px 5px !important;
}

::v-deep .el-collapse-item__wrap {
  border: none;
  background-color: transparent;
}
</style>